home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
UTILENUS
/
MARXMENU.LZH
/
MENUS.EXE
/
SORT.MNU
< prev
next >
Wrap
Text File
|
1991-03-25
|
1KB
|
54 lines
Comment
==========================================================
QuickSort program written in MarxMenu. Works like DOS sort
program. This shows parameter passing and recursive
programming.
Usage: DIR|MARXMENU SORT|MORE
MARXMENU SORT INFILE OUTFILE
==========================================================
EndComment
ClearScreenOnExit Off
var SortBuf Middle
ReadTextFile (ParamStr(2),SortBuf)
Sort(1,NumberOfElements(SortBuf))
WriteTextFile (ParamStr(3),SortBuf)
Procedure Sort (L,R)
var I,J,Swap
I = L
J = R
Middle = SortBuf[(L+R)/2]
repeat
while SortBuf[I] < Middle
I = I + 1
endwhile
while Middle < SortBuf[J]
J = J - 1
endwhile
if I <= J
Swap = SortBuf[J]
SortBuf[J] = SortBuf[I]
SortBuf[I] = Swap
I = I + 1
J = J - 1
endif
until I > J
if (J - L) < (R - I)
if L < J then Sort(L,J);
if I < R then Sort(I,R);
else
if I < R then Sort(I,R);
if L < J then Sort(L,J);
endif
EndProc